package shuogg.test.servletbase;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.io.IOUtils;

@SuppressWarnings(value = { "all" })
public class Redirect extends HttpServlet {

    @Override
    public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        /* 输出一个html文件 */
        OutputStream out = resp.getOutputStream();
        FileInputStream in = new FileInputStream("F:/表单例程.html");
        IOUtils.copy(in, out);

        /* 重定向: 响应头法 */
        resp.setHeader("location", "/ServletBaseTest/OutImage");
        /* 重定向到MyServlet */
        resp.sendRedirect("/ServletBaseTest/OutImage");
        // resp.sendRedirect("OutImage"); //这句等价于上面那一句.
        // 最左边没有斜杠代表根目录在ServletBaseTest
        
        System.out.println("redirect complete!");

    }

    @Override
    public void doPost(HttpServletRequest req, HttpServletResponse resp) {

    }

}
